package com.central.operate.dao;

import com.central.operate.dto.ChartParams;
import com.central.operate.model.LoginInfo;
import com.central.operate.model.OperateRecord;
import com.central.operate.model.RecordTime;
import com.central.operate.vo.RegisterCountChartVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface LoginCountDao {

    int countOnline(Map<String, Object> params);

    List<LoginInfo> findOnlineList(Map<String, Object> params);

    List<RecordTime> recordByH(Map<String, Object> params);

    Integer countOnlineHistory(Map<String, Object> params);

    Integer countLoginHistory(Map<String, Object> params);





    /*
    统计表里查找
     */
    //查找某一天的各个时间段的登录量
    @Select("select startTime,endTime,login FROM operate_record WHERE DATE_FORMAT(startTime,'%Y-%m-%d') = #{startTime}")
    List<OperateRecord> listLoginCountByDay(String startTime);

//    @Select("SELECT UNIX_TIMESTAMP(startTime) * 1000 millisecond, SUM(login) count FROM operate_record WHERE DATE_SUB(#{start_time}, INTERVAL #{consecutive_day} DAY) < date(startTime) AND #{start_time} >= date(startTime) GROUP BY DATE(startTime),HOUR (startTime) div #{interval_hour} ORDER BY millisecond")
//    List<RegisterCountChartVO> listLogin(Map<String, Object> params);
    @Select("SELECT UNIX_TIMESTAMP(startTime) * 1000 millisecond, SUM(login) count FROM operate_record WHERE DATE_SUB(#{startTime}, INTERVAL #{consecutiveDay} DAY) < date(startTime) AND #{startTime} >= date(startTime) GROUP BY DATE(startTime),HOUR (startTime) div #{intervalHour} ORDER BY millisecond")
    List<RegisterCountChartVO> listLogin(ChartParams chartParams);

//    @Select("SELECT UNIX_TIMESTAMP(startTime) * 1000 millisecond, SUM(online) count FROM operate_record WHERE DATE_SUB(#{start_time}, INTERVAL #{consecutive_day} DAY) < date(startTime) AND #{start_time} >= date(startTime) GROUP BY DATE(startTime),HOUR (startTime) div #{interval_hour} ORDER BY millisecond")
//    List<RegisterCountChartVO> listOnline(Map<String, Object> params);

    @Select("SELECT UNIX_TIMESTAMP(startTime) * 1000 millisecond, SUM(online) count FROM operate_record WHERE DATE_SUB(#{startTime}, INTERVAL #{consecutiveDay} DAY) < date(startTime) AND #{startTime} >= date(startTime) GROUP BY DATE(startTime),HOUR (startTime) div #{intervalHour} ORDER BY millisecond")
    List<RegisterCountChartVO> listOnline(ChartParams chartParams);
}
